# 使用官方Ubuntu 22.04镜像作为基础
FROM ubuntu:22.04

# 设置环境变量，避免交互提示
ENV DEBIAN_FRONTEND=noninteractive

ENV LANG=en_US.UTF-8

# 更新系统并安装必要依赖
RUN apt-get update 
RUN apt-get install -y --no-install-recommends \
    wget \
    gdebi-core \
    r-base \
    r-base-dev \
    libapparmor1 \
    libclang-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    libxt6 \
    lsb-release \
    psmisc \
    sudo \
    vim \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt install -y language-pack-zh-hans language-pack-zh-hans-base  fonts-wqy-zenhei fonts-noto-cjk\
    locales locales-all \
    libcairo2-dev libxt-dev \
    && rm -rf /var/lib/apt/lists/*

RUN locale-gen zh_CN.UTF-8    

# 安装RStudio Server
# RUN wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.12.0-369-amd64.deb 
COPY rstudio-server-2023.12.0-369-amd64.deb /opt
RUN gdebi  -n /opt/rstudio-server-2023.12.0-369-amd64.deb

# 安装readxl包
RUN R -e "\
packages <- c('readxl', 'dplyr', 'ggplot2', 'tidyr', 'stringr', 'openxlsx','haven', 'xml2', 'data.table','rlist', 'ggpmisc','tibble','stringr','Matrix','Hmisc','xgboost','ranger'); \
install.packages(packages, repos = 'https://cloud.r-project.org') \
"



# 设置 root 密码（示例：password123）
RUN passwd -d root && \
    echo "root:root" | chpasswd

# RUN mkdir -p /opt/packages

# RUN echo "R_LIBS_USER=\"/opt/packages/\"" >> /root/.Renviron

# 增加规则，允许root登录
RUN echo auth-minimum-user-id=0 > /etc/rstudio/rserver.conf

# 暴露RStudio Server默认端口
EXPOSE 8787

# 启动服务
COPY entrypoint.sh /opt/entrypoint.sh
RUN chmod +x /opt/entrypoint.sh

